<?php
namespace app\saas\controller;

// 微购儿控制器
use app\saas\service\WeService;

class WeController extends BaseController
{
    public function initialize(){
        $this->noCheckTokenAction = ["initializeData", "toLogin", "toModifyTime", "updateInfo", 'getInfo'];
        parent::initialize();
    }

    // 自动交付生成数据
    public function initializeData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(WeService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->initializeData();
        return $this->return_result($this->returnData);
    }

    // 登录
    public function toLogin(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(WeService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toLogin();
        return is_string($this->returnData) ? $this->returnData : $this->return_result($this->returnData);
    }

    // 修改到期时间
    public function toModifyTime(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(WeService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toModifyTime();
        return $this->return_result($this->returnData);
    }

    // 修改商城基本信息
    public function updateInfo(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(WeService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->updateInfo();
        return $this->return_result($this->returnData);
    }

    // 信息
    public function getInfo(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(WeService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getInfo();
        return $this->return_result($this->returnData);
    }
}
